import { QXEvent } from 'qx-util';
import {
	IParam,
	SearchFormActionType,
	ISearchFormAbility,
	ISearchFormControllerParams,
	ISearchFormStore,
	SearchFormController,
	ICtrlEvent,
	ISearchFormController,
	ISearchFormModel,
} from '@/core';
import {
	useFormAction,
	useFormBasic,
	useFormControllerParams,
	useFormProps,
} from '@/hooks/widget/use-search-form';
import { SearchformControlVO } from './default-searchform-vo';
import { model } from './default-searchform-model';
import SearchFormService from '@/core/modules/ctrl-service/searchform-service';
// 基于template/src/widgets/{{appEntities}}/{{ctrls@SEARCHFORM}}-searchform/{{spinalCase ctrl.codeName}}-searchform-hook.ts.hbs生成
/**
 * 获取输入参数
 *
 * @export
 * @return {*}
 */
export function useProps() {
	return {
		...useFormProps(),
	};
}

/**
 * 获取基础数据
 *
 * @export
 * @param {*} props
 * @return {*}
 */
export function useBasic(props: any) {
	return {
		...useFormBasic(model, props),
	};
}

/**
 * 获取行为
 *
 * @export
 */
export function useAction(controller: any) {
	return {
		...useFormAction(controller),
	};
}

/**
 * 获取控制器
 *
 * @export
 * @param {IParam} props
 * @param {QXEvent<ICtrlEvent<SearchFormActionType, ISearchFormAbility>>} evt
 * @return {*}
 */
export function useController(
	props: IParam,
	evt: QXEvent<ICtrlEvent<SearchFormActionType, ISearchFormAbility>>,
	otherParams: IParam = {}
): ISearchFormController<ISearchFormStore, ISearchFormAbility> {
	const params: ISearchFormControllerParams<
		SearchFormActionType,
		ISearchFormAbility
	> = useFormControllerParams<ISearchFormStore, ISearchFormModel>(
		model,
		props,
		evt,
		otherParams
	);
	const ctrlService = new SearchFormService<SearchformControlVO>(
		SearchformControlVO,
		model.entityCodeName
	);
	Object.assign(params, { ctrlService });
	return new SearchFormController(params);
}
